﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace SchedulerControl.Adorners
{
    public class AdornedObject : IAdornedObject
    {
        RotateTransform _rotate;
        private FrameworkElement _adornedElement;

        public AdornedObject(FrameworkElement element, double angle)
            : this(element)
        {
            Angle = angle;
            _metaData = new AppointmentItemMetaData();
        }

        public AdornedObject(FrameworkElement element, double x, double y, double angle) : this(element)
        {
            X = x;
            Y = y;
            Angle = angle;
        }

        public AdornedObject(FrameworkElement element)
        {
            AdornedElement = element;
            AdornedElement.RenderTransformOrigin = new Point(0.5, 0.5);
            _rotate = new RotateTransform();
            AdornedElement.RenderTransform = _rotate;
        }

        #region IAdornedObject Members

        public double Angle
        {
            get { return _rotate.Angle; }
            set { _rotate.Angle = value; }
        }

        public double X
        {
            get { return Canvas.GetLeft(AdornedElement); }
            set { Canvas.SetLeft(AdornedElement, value); }
        }

        public double Y
        {
            get { return Canvas.GetTop(AdornedElement); }
            set { Canvas.SetTop(AdornedElement, value); }
        }

        public double ObjectWidth
        {
            get { return AdornedElement.Width; }
            set { AdornedElement.Width = value; }
        }

        public double ObjectHeight
        {
            get { return AdornedElement.Height; }
            set { AdornedElement.Height = value; }
        }

        public FrameworkElement AdornedElement
        {
            get { return _adornedElement; }
            set { _adornedElement = value; }
        }

        #endregion

        private AppointmentItemMetaData _metaData;
        public AppointmentItemMetaData MetaData
        {
            get { return _metaData; }
            set
            {
                _metaData = value;
            }
        }
    }
}
